package com.ruoyi.web.controller.ring.app;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.ring.domain.RingHeartRate;
import com.ruoyi.ring.domain.dto.RingHeartRateDTO;
import com.ruoyi.ring.domain.vo.RingHeartRateVO;
import com.ruoyi.ring.service.IRingHeartRateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 心率 （APP）
 */
@Slf4j
@RestController
@RequestMapping("/ring/app/ring_heart_rate")
public class AppHeartRateController extends BaseController
{
    @Resource
    private IRingHeartRateService ringHeartRateService;

    /**
     * 上报心率-app
     */
    @Log(title = "上报心率", businessType = BusinessType.INSERT)
    @PostMapping("add-heart-rate")
    public AjaxResult addHeartRate(@RequestBody RingHeartRate ringHeartRate)
    {
        ringHeartRate.setDailyValue(DateUtils.dateTime(DateUtils.YYYY_MM_DD, DateUtils.getDate()));
        ringHeartRate.setEndTime(new Date());
        return toAjax(ringHeartRateService.insertRingHeartRate(ringHeartRate));
    }
    /**
     * 心率最新信息-app
     */
    @GetMapping("/query-heart-rate")
    public AjaxResult queryHeartRate(RingHeartRateDTO ringHeartRateDTO)
    {
        long userId = SecurityUtils.getUserId();
        log.info("心率最新信息queryHeartRate: userId={}, param={}", userId, JSON.toJSONString(ringHeartRateDTO));
        RingHeartRateVO heartRateVO = ringHeartRateService.queryRingHeartRate(ringHeartRateDTO);
        return AjaxResult.success(heartRateVO);
    }
    /**
     * 心率列表-app
     */
    @GetMapping("/query-list")
    public AjaxResult queryList(RingHeartRateDTO ringHeartRateDTO)
    {
        long userId = SecurityUtils.getUserId();
        log.info("心率列表queryList: userId={}, param={}", userId, JSON.toJSONString(ringHeartRateDTO));
        List<RingHeartRate> list = ringHeartRateService.queryRingHeartRateList(ringHeartRateDTO);
        return AjaxResult.success(list);
    }

}
